package com.exam.api.common.enums;

import com.exam.api.common.exception.GlobalException;
import com.exam.api.common.web.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author bcheng
 * @Create 2024/1/3 16:00
 * @Description 登录设备信息
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum LoginDevice {

    /**
     * PC端
     */
    PC(0, "PC", "PC端"),

    /**
     * APP端
     */
    APP(1, "APP", "APP端");
    /**
     * 登录设备Code
     */
    private final Integer code;
    /**
     * 登录设备类型
     */
    private final String type;
    /**
     * 登录设备名称
     */
    private final String name;


    public static LoginDevice getLoginDevice(Integer deviceId) {
        LoginDevice device;
        if (LoginDevice.PC.getCode().equals(deviceId)) {
            device = LoginDevice.PC;
        } else if (LoginDevice.APP.getCode().equals(deviceId)) {
            device = LoginDevice.APP;
        } else {
            throw new GlobalException(ResultCode.SUPPORTED_DEVICE_LOGIN);
        }
        return device;
    }
}
